package com.maxd.service.userinfo;

import com.maxd.model.*;
import com.maxd.respository.userinfo.UserLogRepository;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description 用户登录日志
 * @author fang
 * @date 2021-03-23
 */
@Service
@Slf4j
public class UserLogServiceImpl implements IUserLogService {

    @Autowired
    private UserLogRepository userLogRepository;


    @Override
    public UserLog insertUserLog(Long userId){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        UserLog userLog = selectUserLog(userId, time);
        if(userLog==null){
            userLog=new UserLog();
            userLog.setUserId(userId);
            userLog.setUpdateTime(time);
        }
        return userLogRepository.save(userLog);
    }


    @Override
    public UserLog selectUserLog(Long userId,String time){
        return userLogRepository.selectUserLog(userId, time);
    }



}